package com.ymatou.iapi.userservice.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.iapi.userservice.parameter.UserBriefInfoBean;
import com.ymatou.iapi.userservice.service.UserBriefInfoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
/**
*获取用户简要信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UserBriefInfo{
	private static UserBriefInfoBean userbriefinfoBean;
	private static UserBriefInfoCall userbriefinfoCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取用户简要信息");
	}

	@Before
	public void caseUp() {
		userbriefinfoBean=new UserBriefInfoBean();
		userbriefinfoCall=new UserBriefInfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(userbriefinfoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UserBriefInfo_001() {
		Logger.start(true,"获取用户简要信息成功");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			int uid = urrc.getUserid();
			userbriefinfoBean.setUserId(uid);
			userbriefinfoCall.setData(userbriefinfoBean);
			userbriefinfoCall.callService();			
			Logger.verifyEquals("200", userbriefinfoCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("true", userbriefinfoCall.getString("Success"), "验证Success");
			JsonElement jsonElement=userbriefinfoCall.getJsonObject().get("Result");
			Logger.verifyEquals(regbean.getLoginId(), jsonElement.getAsJsonObject().get("LoginId").getAsString(), "验证LoginId");
			Logger.verifyEquals(regbean.getLoginMobile(), jsonElement.getAsJsonObject().get("LoginMobile").getAsString(), "验证LoginMobile");
			// 默认头像地址
			Logger.verifyEquals("1", jsonElement.getAsJsonObject().get("UserLevel").getAsString(), "验证UserLevel");
			Logger.verifyEquals(regbean.getRegisterType(), jsonElement.getAsJsonObject().get("UserType").getAsInt(), "验证UserType");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_UserBriefInfo_002() {
		Logger.start(true,"不输入userid失败");
		try {
			userbriefinfoCall.setData(userbriefinfoBean);
			userbriefinfoCall.callService();			
			Logger.verifyEquals("200", userbriefinfoCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("true", userbriefinfoCall.getString("Success"), "验证Success");
			Logger.verifyIsNull(userbriefinfoCall.getJsonObject().get("Result"),"验证Result为空");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}